import { Controller, Get, Post, Body, Param, Request, Query } from '@nestjs/common';
import { SupplierService } from './supplier.service';
import { CreateSupplierDto } from './dto/create-supplier.dto';

@Controller('supplier')
export class SupplierController {
  constructor(private readonly supplierService: SupplierService) {}

  @Post('save')
  async create(@Body() createSupplierDto: CreateSupplierDto, @Request() req: any) {
    const result = await this.supplierService.create(createSupplierDto, req.tokenInfo );
    return { 
      message: result ? '操作成功': '失败'
    }
  }

  @Get('load')
  async findAll(@Query() query: any) {
    const [data, total] = await this.supplierService.findAll(query);
    return {
      data,
      total
    }
  }
  @Get('loadBySelect')
  async findAllBySelect(@Query() query: any) {
    const data = await this.supplierService.findAllBySelect(query);
    return {
      data
    }
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.supplierService.findOne(+id);
  }

  @Get('delete/:id')
  async delete(@Param('id') id: string) {
    const result = await this.supplierService.delete(id);
    return { 
      message: result ? '完全删除成功': '失败'
    }
  }
  @Get('remove/:id')
  async remove(@Param('id') id: string) {
    const result = await this.supplierService.remove(id);
    return { 
      message: result ? '删除成功': '失败'
    }
  }
}
